import logging
import redis


class Config(object):
    DEBUG = True

    # 为数据库添加配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # 在请求结束后，会自动执行一次 db.session.commit() 操作
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # redis的配置
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379

    SECRET_KEY = 'EjpNVSNQTyGi1VvWECj9TvC/+kq3oujee2kTfQUs8yCM6xX9Yjq52v54g+HVoknA'

    # 指定session保存到redis中
    SESSION_TYPE = 'redis'
    # 让cookie中的session_id被加密签名处理
    SESSION_USE_SIGNER = True
    # 使用 redis 的实例
    SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    # session的有效期
    PERMANENT_SESSION_LIFETIME = 3600 * 24

    LOG_LEVEL = logging.DEBUG


class DevelopmentConfig(Config):
    DEBUG = True


class ProductionConfig(Config):
    DEBUG = False
    LOG_LEVEL = logging.ERROR


class TestingConfig(Config):
    DEBUG = True
    TESTING = True


config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'testing': TestingConfig
}
